
/*
*Released on 28th June 2008.
*Any violations can be reported at paritosh@wikiocean.net
*What is treated as violations can be found at www.wikiocean.net/ppl1-voilations*
******************************************************************************
* The contents of this file are subject to POOL Public License 1.0 and later.
* POOL Public License is based on Affero GPL v3 and additional conditions.
* ("License"); You may not use this file except in compliance with the License
* You may obtain a copy of the Affero GPL v3 License at http://www.gnu.org/licenses/agpl.html
* You may obtain a copy of the POOL Public License 1.0 or later at www.wikiocean.net/license/ppl.html
* Software distributed under POOL Public License 1.0 is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
* the specific language governing rights and limitations under the License.
* The Initial Developer of the Original Code is Paritosh Pungaliya (C) 2008. All Rights Reserved.
******************************************************************************
* Objective of the additional terms (license)
* 1) Is to extend the software freedom to freedom to work.
* 2) To ensure that knowledge is free from monopoly of agencies.
* 3) To avoid a situation where big corporate or investor can buy out free software groups and companies and then start milking the communities built around it.
* (this trend can be seen how the freedom is curtailed in companies that get Venture Capital funding.)
******************************************************************************
*/

package  scheduler;

import java.io.File;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Hashtable;

import logger.PoolLogger;

import pool.bean.Property_details_Bean;

import utility.MessageGenerator;
import utility.PeriodDate;
import User.Uservalidation;
import control.Control;
import control.RequestParameter;

import dbmanager.DBManager;
import dbmanager.GetIdName;

public class UpdateSchedule
{
	Hashtable<Object, Object> scheduletable =new Hashtable<Object, Object>();
	String startdate="startdate";
	String enddate="enddate";
	String currentdate = "currentdate";
	String pattern  = "yyyy-MM-dd";
	String period = "period";
	String DAY="day";
	GetIdName gid;
	String object;
	String USERNAME="+911234567891";
	PoolLogger pl;
	
	public UpdateSchedule() {
		// logger
		pl = (PoolLogger) PoolLogger.getLogger(this.getClass().getName());
	}
	
	public void setData(Hashtable<Object, Object> schedule,String object)
    {
    	this.scheduletable.putAll(schedule);
    	this.gid = new GetIdName();
    	this.object =object;
    }
    
    public boolean getResult()
    {	
		try
		{	
			PeriodDate perioddate= new PeriodDate();
			SimpleDateFormat sdm = new SimpleDateFormat(this.pattern);
			String date = sdm.format(new Date());
			Date d = sdm.parse(date);
			date = sdm.format(d);
			period = gid.getId(scheduletable.get(period).toString());
			if(scheduletable.containsKey(startdate))
			{
				startdate =  scheduletable.get(startdate).toString();
				currentdate =scheduletable.get(currentdate).toString();
				int i = perioddate.compareDate(currentdate, currentdate);
				if(i==1)
				{		
					return false;
				}	
			}
			if(scheduletable.containsKey(enddate))
			{
				enddate =  scheduletable.get(enddate).toString();
				int i = perioddate.compareDate(enddate, date);
				if(i<0)
				{
					return false;
				}	
			}
			if(scheduletable.containsKey(currentdate))
			{
				currentdate =scheduletable.get(currentdate).toString();				
				int i=perioddate.compareDate(currentdate, date);
				if(i==0)
				{
					if(scheduletable.containsKey(period))
					{
						String nextdate= perioddate.getNextDate(period,startdate);
						
					}
					return true;
				}
			}
		} catch (Exception e) 
		{	
			e.printStackTrace();
			return false;
		}
		return true;
    }
}
